package com.ruoyi.project.vehicle.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.vehicle.domain.BinsMaintenanceInfo;
import com.ruoyi.project.vehicle.service.IBinsMaintenanceInfoService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 维修记录Controller
 * 
 * @author administrator
 * @date 2025-04-03
 */
@RestController
@RequestMapping("/vehicle/recode")
public class BinsMaintenanceInfoController extends BaseController
{
    @Autowired
    private IBinsMaintenanceInfoService binsMaintenanceInfoService;

    /**
     * 查询维修记录列表
     */
    @PreAuthorize("@ss.hasPermi('vehicle:recode:list')")
    @GetMapping("/list")
    public TableDataInfo list(BinsMaintenanceInfo binsMaintenanceInfo)
    {
        startPage();
        if (binsMaintenanceInfo.getDeptId() == null){
            binsMaintenanceInfo.setDeptId(getCommonDeptId());
        }
        List<BinsMaintenanceInfo> list = binsMaintenanceInfoService.selectBinsMaintenanceInfoList(binsMaintenanceInfo);
        return getDataTable(list);
    }

    /**
     * 导出维修记录列表
     */
    @PreAuthorize("@ss.hasPermi('vehicle:recode:export')")
    @Log(title = "维修记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BinsMaintenanceInfo binsMaintenanceInfo)
    {
        List<BinsMaintenanceInfo> list = binsMaintenanceInfoService.selectBinsMaintenanceInfoList(binsMaintenanceInfo);
        ExcelUtil<BinsMaintenanceInfo> util = new ExcelUtil<BinsMaintenanceInfo>(BinsMaintenanceInfo.class);
        util.exportExcel(response, list, "维修记录数据");
    }

    /**
     * 获取维修记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('vehicle:recode:query')")
    @GetMapping(value = "/{flowNo}")
    public AjaxResult getInfo(@PathVariable("flowNo") Integer flowNo)
    {
        return success(binsMaintenanceInfoService.selectBinsMaintenanceInfoByFlowNo(flowNo));
    }

    /**
     * 新增维修记录
     */
    @PreAuthorize("@ss.hasPermi('vehicle:recode:add')")
    @Log(title = "维修记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BinsMaintenanceInfo binsMaintenanceInfo)
    {
        return toAjax(binsMaintenanceInfoService.insertBinsMaintenanceInfo(binsMaintenanceInfo));
    }

    /**
     * 修改维修记录
     */
    @PreAuthorize("@ss.hasPermi('vehicle:recode:edit')")
    @Log(title = "维修记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BinsMaintenanceInfo binsMaintenanceInfo)
    {
        return toAjax(binsMaintenanceInfoService.updateBinsMaintenanceInfo(binsMaintenanceInfo));
    }

    /**
     * 删除维修记录
     */
    @PreAuthorize("@ss.hasPermi('vehicle:recode:remove')")
    @Log(title = "维修记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{flowNos}")
    public AjaxResult remove(@PathVariable Integer[] flowNos)
    {
        return toAjax(binsMaintenanceInfoService.deleteBinsMaintenanceInfoByFlowNos(flowNos));
    }
}
